package jmine.tec.services.api;

import java.util.LinkedList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * Entidade que encapsula um conjunto de servicos que devem ser validados/executados.
 * 
 * @author Rafael Volpato
 */
public class ServicesPage {

    protected static Log log = LogFactory.getLog(ServicesPage.class);

    private String name;

    private List<Service<?>> services;

    private boolean dryrun = false;

    /**
     * Construtor padrao.
     */
    public ServicesPage() {
        this.services = new LinkedList<Service<?>>();
    }

    /**
     * Seta o nome da servicesPage
     * 
     * @param name nome
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return o nome da servicesPage
     */
    public String getName() {
        return this.name;
    }

    /**
     * @return the dryrun
     */
    public boolean isDryrun() {
        return this.dryrun;
    }

    /**
     * @param dryrun the dryrun to set
     */
    public void setDryrun(boolean dryrun) {
        this.dryrun = dryrun;
    }

    /**
     * Retorna a lista de servicos associados a essa servicesPage.
     * 
     * @return a lista de servicos associados a essa servicesPage
     */
    public List<Service<?>> getServices() {
        return this.services;
    }

    /**
     * Seta a lista de servicos dessa services page e injeta essa services page nos servicos.
     * 
     * @param services lista de servicos
     */
    public void setServices(List<Service<?>> services) {
        this.services = services;
        for (Service<?> service : services) {
            service.setServicesPage(this);
        }
    }

    /**
     * Adiciona um servico na lista de servicos da servicesPage.
     * 
     * @param service servico
     * @return self
     */
    public ServicesPage addService(Service<?> service) {
        this.services.add(service);
        service.setServicesPage(this);
        return this;
    }
}